from pydantic import BaseModel, Field
from typing import Optional, Dict, Any


class DataPermissionRuleCreate(BaseModel):
    """创建数据权限规则的参数模型"""
    name: str = Field(..., description="规则名称")
    rule_code: str = Field(..., description="规则编码")
    table_name: str = Field(..., description="目标表名")
    logical_operator: Optional[str] = Field("OR", description="多条件组合方式: AND/OR")
    condition_type: str = Field(..., description="条件类型：eq,in,like,between等")
    config_json: Dict[str, Any] = Field(..., description="权限配置JSON")
    description: Optional[str] = Field(None, description="规则描述")
    status: Optional[bool] = Field(True, description="是否启用")


class DataPermissionRuleUpdate(BaseModel):
    """更新数据权限规则的参数模型"""
    name: Optional[str] = Field(None, description="规则名称")
    rule_code: Optional[str] = Field(None, description="规则编码")
    table_name: Optional[str] = Field(None, description="目标表名")
    logical_operator: Optional[str] = Field(None, description="多条件组合方式: AND/OR")
    condition_type: Optional[str] = Field(None, description="条件类型：eq,in,like,between等")
    config_json: Optional[Dict[str, Any]] = Field(None, description="权限配置JSON")
    description: Optional[str] = Field(None, description="规则描述")
    status: Optional[bool] = Field(None, description="是否启用")


class RoleDataPermissionCreate(BaseModel):
    """创建角色数据权限关联的参数模型"""
    role_id: int = Field(..., description="角色ID")
    rule_id: int = Field(..., description="数据权限规则ID")
    status: Optional[bool] = Field(True, description="是否启用")


class RoleDataPermissionUpdate(BaseModel):
    """更新角色数据权限关联的参数模型"""
    status: Optional[bool] = Field(None, description="是否启用")


class RoleDataPermissionBatchCreate(BaseModel):
    """批量创建角色数据权限关联的参数模型"""
    role_id: int = Field(..., description="角色ID")
    rule_ids: list[int] = Field(..., description="数据权限规则ID列表")
    status: Optional[bool] = Field(True, description="是否启用")